<?php

class Photogallery extends Module{

	public function __construct(){
		$this->author = "Tomáš Voslař";
		$this->name = "Fotogalerie";
		$this->presenter = "Photogallery";
		$this->version = "0.1";
		$this->params = "seo_title";
	}

	public function getSql(){
			
		dibi::query("CREATE TABLE IF NOT EXISTS `" . TABLE_PREFIX . "photogallery` (
  				`id_photogallery` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  				`id_menu` mediumint(8) unsigned NOT NULL,
  				`date` datetime NOT NULL,
  				`title` varchar(255) NOT NULL,
  				`seo_title` varchar(255) NOT NULL,
  				`text` text NOT NULL,
  				PRIMARY KEY (`id_photogallery`),
  				KEY (`id_menu`)
				) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;
				");
		
		dibi::query("CREATE TABLE IF NOT EXISTS `" . TABLE_PREFIX . "photogallery_items` (
  				`id_photo` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
  				`id_photogallery` mediumint(8) unsigned NOT NULL,
  				`date` datetime NOT NULL,
  				`title` varchar(255) NOT NULL,
  				`id_file` int(10) unsigned NOT NULL,
  				`hlavni` tinyint(1) NOT NULL,
  				PRIMARY KEY (`id_photo`),
  				KEY (`id_file`),
  				KEY (`id_photogallery`)
				) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;
				");
		
		dibi::query("ALTER TABLE `" . TABLE_PREFIX . "photogallery`
 						 ADD CONSTRAINT `photogallery_menu_ibfk_1` FOREIGN KEY (`id_menu`) REFERENCES `" . TABLE_PREFIX . "menu` (`id_menu`) ON DELETE CASCADE ON UPDATE CASCADE;");
			
		
		dibi::query("ALTER TABLE `" . TABLE_PREFIX . "photogallery_items`
 						 ADD CONSTRAINT `photogallery_ibfk_1` FOREIGN KEY (`id_photogallery`) REFERENCES `" . TABLE_PREFIX . "photogallery` (`id_photogallery`) ON DELETE CASCADE ON UPDATE CASCADE;");
			
		
		dibi::query("ALTER TABLE `" . TABLE_PREFIX . "photogallery_items`
 						 ADD CONSTRAINT `photogallery_items_ibfk_1` FOREIGN KEY (`id_file`) REFERENCES `" . TABLE_PREFIX . "files` (`id_file`) ON DELETE CASCADE ON UPDATE CASCADE;");
			
	}

}

?>